package ungdung_quanlymathang;

import com.example.quanly_mathang.R;
import android.os.Bundle;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;


public class Ac_capnhatmathang extends Activity {
	Bundle bd;
	 EditText ed1;
	 EditText ed2;
	 EditText ed3;
	 EditText ed4;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.capnhatmathang);
        ed1=(EditText)findViewById(R.id.editText1);
    	ed2=(EditText)findViewById(R.id.editText2);
    	ed3=(EditText)findViewById(R.id.editText3);
    	ed4=(EditText)findViewById(R.id.editText4);
        bd=new Bundle();
        bd=this.getIntent().getExtras();
        TextView tx6=(TextView)findViewById(R.id.textView6); 
        tx6.setText(bd.getString("tennguoidung")+"!Đăng xuất");
        ed1.setText(bd.getString("tenmathang"));
        ed2.setText(bd.getString("giamathang"));
        ed3.setText(bd.getString("nhasanxuat"));
        ed4.setText(bd.getString("ngaycapnhat"));
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.capnhatmathang, menu);
        return true;
    }
    public void dangxuat(View v){
    	Intent it=new Intent(this.getApplicationContext(),Ac_dangnhap.class);
    	startActivity(it);
    }

    public void capnhat_mathang(View v){
    	if (ed1.getText().toString().trim().equals("") || ed2.getText().toString().trim().equals("")||ed3.getText().toString().trim().equals("")||ed4.getText().toString().trim().equals(""))
    	{	
    		AlertDialog.Builder al=new AlertDialog.Builder(this);
		    al.setMessage("Hãy điền đầy đủ thông tin mặt hàng?").setPositiveButton("OK", null).show();
    	}
    	else{
    	Cosodulieu csdl=new Cosodulieu(this);
    	mat_hang mh=new mat_hang();
    	mh.set_id_mathang(Integer.valueOf(bd.getString("id_mh")));
    	mh.set_id_nguoidung(Integer.valueOf(bd.getString("id_nd")));
    	mh.set_tenmathang(ed1.getText().toString());
    	mh.set_gia_mathang(ed2.getText().toString());
    	mh.set_nha_sanxuat(ed3.getText().toString());
    	mh.set_ngay_capnhat(ed4.getText().toString());
    	csdl.capnhat_mathang(mh);
    	AlertDialog.Builder al=new AlertDialog.Builder(this);
	    al.setMessage("Cập nhật mặt hàng thành công!").setPositiveButton("OK", null).show();
    	}
    	ed1.setText("");
    	ed2.setText("");
    	ed3.setText("");
    	ed4.setText("");
    }
    public void xemmathang(View v){
    	Intent it=new Intent(this.getApplicationContext(),Ac_danhsachmathang.class);
    	Bundle bd2=new Bundle();
    	bd2.putString("ten_nguoidung", bd.getString("tennguoidung"));
    	bd2.putString("idnd", bd.getString("id_nd"));
    	bd2.putString("matkhau", bd.getString("mkhau"));
    	it.putExtras(bd2);
    	startActivity(it);
    
    }
}
